const express = require('express'); //引入express模块
const db = require('../db'); //引入user模块

//路由中间件
const router = express.Router();
module.exports = router;

//查询
router.get('/guan', async (req, res) => {
    const {
        name
    } = req.query;

    const sql = `select * from hu_ji_xin_xi where name=name`
    console.log('heresql=', sql)
    const data = await db(sql);

    console.log('data',data);



    res.send(
        data
    )
});

router.get('/guan1', async (req, res) => {
    const {
        keyword
    } = req.query;
    // console.log('data',data);
    const sql = `select * from hu_ji_xin_xi where name or id or gender or nation or id_number or Student_number like '%${keyword}%'`
    console.log('heresql=', sql)
    const data = await db(sql);

    // console.log('data',data);

    res.send(
        data
    )
});

//删除
router.delete('/:id',async (req,res)=>{
    const {id} = req.params;
   
    const sql = `DELETE FROM hu_ji_xin_xi WHERE id=${id}`

    // console.log('sql=',sql)
    
    const data = await db(sql)
    res.send({
        code:200,
        data:data[0],
        msg:'success'
    })
})